package com.plian.system.service.cqzc.bondsrepayment;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.plian.Tools.*;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.cache.UserCache;
import com.plian.system.config.exception.MyRuntimeException;
import com.plian.system.constant.sys.FormTypeConstant;
import com.plian.system.constant.yth.YthConstant;
import com.plian.system.dao.cqzc.bondissue.bondIssueDao;
import com.plian.system.dao.cqzc.bondsrepayment.BondsRepaymentDao;
import com.plian.system.entity.fr.bonds.BondsIssue;
import com.plian.system.entity.fr.bonds.BondsRepayment;
import com.plian.system.entity.sys.ApprovalMessage;
import com.plian.system.mapper.fr.bonds.BondsRepaymentMapper;
import com.plian.system.model.CommonCode;
import com.plian.system.model.ListResult;
import com.plian.system.model.ObjResult;
import com.plian.system.model.page.Page;
import com.plian.system.mybatis.base.BaseFlowService;
import com.plian.system.service.cqzc.bondissue.BondsIssueService;
import com.plian.system.service.sys.code.IFormCodeService;
import com.plian.system.service.sys.file.FileService;
import com.plian.system.service.sys.message.IApprovalMessageService;
import com.plian.system.service.sys.orgzation.IOrgService;
import com.plian.system.service.wf.FormWorkflowService;
import com.plian.system.vo.yth.YthResult;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.plian.system.constant.sys.FormStatusConstant.*;
import static com.plian.system.constant.sys.FormTypeConstant.CQZC_BONDSREPAYMENT;

/**
 * 说明：债券偿还
 */
@Service
public class BondsRepaymentService extends ServiceImpl<BondsRepaymentMapper, BondsRepayment> implements BaseFlowService {
    @Autowired
    BondsRepaymentDao bondsrepaymentDao;
    @Autowired
    bondIssueDao bondIssueDao;
    @Autowired
    FileService fileService;
    @Autowired
    FormWorkflowService formWorkflowService;
    @Autowired
    IFormCodeService formCodeService;
    @Autowired
    private IOrgService orgService;
    @Autowired
    private BondsIssueService bondsIssueService;
    @Autowired
    private IApprovalMessageService approvalMessageService;
    @Autowired
    bondIssueDao bondissueDao;
    /**
     * logger属性.
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(BondsRepaymentService.class);

    /**
     * 保存
     *
     * @param pd
     * @return
     */
    public ObjResult save(PageData pd) {
        try {
            isData(pd);
            String id = UuidUtil.get32UUID();
            pd.put("id", id);
            pd.put("status", "0");
            pd.put("orgId", TokenUtil.getTokenOrgId());
            pd.put("createDate", new Date());
            pd.put("formType", FormTypeConstant.CQZC_BONDSREPAYMENT);
            pd.put("code", formCodeService.getCode(FormTypeConstant.CQZC_BONDSREPAYMENT));
            pd.put("createUser", TokenUtil.getTokenUserId());
            pd.put("updateUser", TokenUtil.getTokenUserId());
            pd.put("updateTime", new Date());
            if(StringUtil.isNotBlank(pd.getString("bondIssueId"))&&StringUtil.isNotBlank(pd.getString("repaymentDate"))){//20241218 zsk 判断是否在债券到期日结清债券
                PageData issuePd=bondissueDao.findbyid(pd.getString("bondIssueId"));
                if(issuePd!=null&&StringUtil.isNotBlank(issuePd.getString("bondMaturity"))){

                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    Date bondMaturity = sdf.parse(issuePd.getString("bondMaturity"));//债券到期日
                    Date repaymentDate = sdf.parse(pd.getString("repaymentDate"));//债券到期日
                    int comparison = bondMaturity.compareTo(repaymentDate);
                    PageData p = new PageData();
                    p.put("bondIssueId", id);
                    //累计已偿还金额
                    String sumRepay = bondsrepaymentDao.RemainingBalance(p);
                    Double suRepayDouble=StringUtil.isNotBlank(sumRepay)?Double.parseDouble(sumRepay):0D;//累计已经偿还
                    Double issueAmountDouble=StringUtil.isNotBlank(issuePd.getString("issueAmount"))?Double.parseDouble(issuePd.getString("issueAmount")):0D;//发行金额
                    Double repaymentOfPrincipalDouble=StringUtil.isNotBlank(pd.getString("repaymentOfPrincipal"))?Double.parseDouble(pd.getString("repaymentOfPrincipal")):0D;//当前数据更新偿还金额
                    boolean bo=issueAmountDouble==suRepayDouble+repaymentOfPrincipalDouble;
                    if(comparison==0&&bo){
                        pd.put("status","9");
                    }

                }
            }

            bondsrepaymentDao.save(pd);

            HashMap<String, Object> processVariable = new HashMap<>();
            if(!(pd.getString("status").equals("9"))){
                formWorkflowService.startProcessAndSimulate(id, pd.getString("formType"), processVariable);
            }else{//如果是不需要审批的要处理后续问题
                operation(pd);
            }
            //保存附件
            fileService.saveAll(id, (List<HashMap>) pd.get("list_doc"));
            ObjResult objResult = new ObjResult(CommonCode.SUCCESS);
            return objResult;
        } catch (MyRuntimeException e) {
            throw e;
        } catch (Exception e) {
            LOGGER.error(ExceptionUtils.getStackTrace(e));
            return new ObjResult(CommonCode.ERROR);
        }
    }

    /**
     * 校验可偿还额度
     *
     * @return
     */
    public void isData(PageData pd) throws Exception {
        //偿还金额
        double repaymentOfPrincipal = Tools.isEmpty(pd.getString("repaymentOfPrincipal")) ? 0 : Double.valueOf(pd.getString("repaymentOfPrincipal"));
        //剩余可偿还金额
        double principalOfSurvivingBonds1 = Tools.isEmpty(pd.getString("balance")) ? 0 : Double.valueOf(pd.getString("balance"));
        //剩余发行金额
        double principalOfSurvivingBonds = Double.valueOf(RemainingBalance(pd.getString("bondIssueId")));
        if (pd.containsKey("isReport")) {
            if (principalOfSurvivingBonds != principalOfSurvivingBonds1) {
                ObjResult objResult = new ObjResult(CommonCode.VALIDATE);
                objResult.setMessage("存续余额发生改变,请重新保存后上报!!!");
                throw new MyRuntimeException(objResult);
            }
        }
        if (repaymentOfPrincipal > principalOfSurvivingBonds) {
            ObjResult objResult = new ObjResult(CommonCode.VALIDATE);
            objResult.setMessage("存续余额不足!!!");
            throw new MyRuntimeException(objResult);
        }
    }
    public ObjResult isDataTwo(PageData pd) throws Exception {
        //偿还金额
        double repaymentOfPrincipal = Tools.isEmpty(pd.getString("repaymentOfPrincipal")) ? 0 : Double.valueOf(pd.getString("repaymentOfPrincipal"));
        //剩余可偿还金额
        double principalOfSurvivingBonds1 = Tools.isEmpty(pd.getString("balance")) ? 0 : Double.valueOf(pd.getString("balance"));
        //剩余发行金额
        double principalOfSurvivingBonds = Double.valueOf(RemainingBalance(pd.getString("bondIssueId")));

        if (pd.containsKey("isReport")) {
            if (principalOfSurvivingBonds != principalOfSurvivingBonds1) {
                ObjResult objResult = new ObjResult(CommonCode.FAIL);
                objResult.setMessage("存续余额发生改变,请重新保存后上报!!!");
//                throw new MyRuntimeException(objResult);
                return objResult;
            }
        }
        if (repaymentOfPrincipal > principalOfSurvivingBonds) {
            ObjResult objResult = new ObjResult(CommonCode.FAIL);
            objResult.setMessage("存续余额不足!!!");
            return objResult;
//            throw new MyRuntimeException(objResult);
        }
        ObjResult objResult = new ObjResult(CommonCode.SUCCESS);
        return objResult;
    }
    /**
     * 修改
     *
     * @param pd
     * @return
     */
    public ObjResult edit(PageData pd) {
        try {
            isData(pd);
            String id = pd.getString("id");
            pd.put("updateUser", TokenUtil.getTokenUserId());
            pd.put("updateTime", new Date());
            if(StringUtil.isNotBlank(pd.getString("bondIssueId"))&&StringUtil.isNotBlank(pd.getString("repaymentDate"))){//20241218 zsk 判断是否在债券到期日结清债券
                PageData issuePd=bondissueDao.findbyid(pd.getString("bondIssueId"));
                PageData oldRepaymentPd = bondsrepaymentDao.findbyid(id);
                if(issuePd!=null&&StringUtil.isNotBlank(issuePd.getString("bondMaturity"))){

                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    Date bondMaturity = sdf.parse(issuePd.getString("bondMaturity"));//债券到期日
                    Date repaymentDate = sdf.parse(pd.getString("repaymentDate"));//债券到期日
                    int comparison = bondMaturity.compareTo(repaymentDate);
                    PageData p = new PageData();
                    p.put("bondIssueId", id);
                    //累计已偿还金额
                    String sumRepay = bondsrepaymentDao.RemainingBalance(p);
                    Double suRepayDouble=StringUtil.isNotBlank(sumRepay)?Double.parseDouble(sumRepay):0D;//累计已经偿还
                    Double issueAmountDouble=StringUtil.isNotBlank(issuePd.getString("issueAmount"))?Double.parseDouble(issuePd.getString("issueAmount")):0D;//发行金额
                    Double repaymentOfPrincipalDouble=StringUtil.isNotBlank(pd.getString("repaymentOfPrincipal"))?Double.parseDouble(pd.getString("repaymentOfPrincipal")):0D;//当前数据更新偿还金额
                    Double oldRepaymentPdDouble=0D;//当前数据历史偿还金额
                    if(oldRepaymentPd.getString("status").equals("1")||oldRepaymentPd.getString("status").equals("3")){
                        oldRepaymentPdDouble=StringUtil.isNotBlank(oldRepaymentPd.getString("repaymentOfPrincipal"))?Double.parseDouble(oldRepaymentPd.getString("repaymentOfPrincipal")):0D;
                    }


                    boolean bo=issueAmountDouble==suRepayDouble+repaymentOfPrincipalDouble-oldRepaymentPdDouble;
                    if(comparison==0&&bo){
                        pd.put("status","9");
                    }

                }
            }
            bondsrepaymentDao.edit(pd);
            //修改附件
            fileService.edit(id, (List<HashMap>) pd.get("list_doc"));
            if(pd!=null&&pd.getString("status")!=null&&pd.getString("status").equals("9")){//如果是不需要审批的要处理后续问题
                operation(pd);
            }
            ObjResult objResult = new ObjResult(CommonCode.SUCCESS);
            return objResult;
        } catch (MyRuntimeException e) {
            throw e;
        } catch (Exception e) {
            LOGGER.error(ExceptionUtils.getStackTrace(e));
            return new ObjResult(CommonCode.ERROR);
        }
    }

    /**
     * 查询列表
     *
     * @return
     */
    public ListResult listPage(PageData pd) {
        ListResult listResult;
        try {
            pd.put("orgId", TokenUtil.getTokenOrgId());
            boolean isPage = true;
            if (pd.containsKey("isPage")) {
                isPage = (boolean) pd.get("isPage");
            }
            Page page = new Page(isPage, pd);
            List<PageData> list = bondsrepaymentDao.listPage(page);
            listResult = new ListResult(CommonCode.SUCCESS);
            listResult.setList(list);
            listResult.setTotal(page.getTotal());
        } catch (Exception e) {
            LOGGER.error(ExceptionUtils.getStackTrace(e));
            listResult = new ListResult(CommonCode.ERROR);
        }
        return listResult;
    }

    /**
     * 根据id查询
     *
     * @param pd
     * @return
     */
    public ObjResult findbyid(PageData pd) {
        ObjResult objResult;
        String id = pd.getString("id");
        try {
            PageData p = bondsrepaymentDao.findbyid(id);
            objResult = new ObjResult(CommonCode.SUCCESS);
            objResult.setPageData(p);
            return objResult;
        } catch (Exception e) {
            LOGGER.error(ExceptionUtils.getStackTrace(e));
            objResult = new ObjResult(CommonCode.ERROR);
            return objResult;
        }
    }

    public ObjResult del_ids(List<String> ids) {
        try {
            ObjResult objResult = new ObjResult(CommonCode.SUCCESS);
            bondsrepaymentDao.del_ids(ids);
            for (String s : ids) {
                formWorkflowService.deleteProcessInstance(s);
            }
            return objResult;
        } catch (Exception e) {
            LOGGER.error(ExceptionUtils.getStackTrace(e));
            return new ObjResult(CommonCode.ERROR);
        }
    }

    /**
     * 提交单据
     *
     * @param formId 单据id
     */
    public HashMap<String, Object> commit(String formId) {
        ObjResult obj=null;
        try {
            PageData pd = bondsrepaymentDao.findbyid(formId);
            pd.put("isReport", "1");
            obj=isDataTwo(pd);
            if(!obj.isSuccess()){
                throw new MyRuntimeException(obj.getMessage());
            }
            PageData pageData = new PageData();
            pageData.put("status", String.valueOf(FLOW));
            ArrayList<String> ids = new ArrayList<>();
            ids.add(formId);
            pageData.put("id", ids);
            bondsrepaymentDao.refer(pageData);
        } catch (Exception e) {
            log.error(ExceptionUtils.getStackTrace(e));
            if(obj!=null&&!obj.isSuccess()){
                throw new MyRuntimeException(obj);
            }else{
                throw new MyRuntimeException("上报失败");
            }

        }
        //将需要提交的流程变量返回，用于工作流侧
        return new HashMap<String, Object>();
    }

    private void operation(PageData pd) throws Exception {
        //超短期
        if ("5".equals(pd.getString("bondVarieties"))) {
            PageData p = bondIssueDao.findbyid(pd.getString("bondIssueId"));
            //偿还本金
            BigDecimal repaymentOfPrincipal = new BigDecimal(pd.getString("repaymentOfPrincipal"));
            //剩余可发债额度
            BigDecimal remaining_issuable_amount = new BigDecimal(p.getString("remainingIssuableAmount"));
            //操作存续余额
            String amount = remaining_issuable_amount.add(repaymentOfPrincipal).toPlainString();
            p.put("remainingIssuableAmount", amount);
            bondIssueDao.edit(p);

        }
    }

    /**
     * 退回单据
     *
     * @param formId 单据id
     */
    public Boolean reject(String formId, int formState, String comment){
        PageData pageData = new PageData();
        pageData.put("status", String.valueOf(formState));
        pageData.put("id", Collections.singletonList(formId));
        try {
            bondsrepaymentDao.refer(pageData);
//            saveMessage(formId, false, comment);
        } catch (Exception e) {
            log.error(ExceptionUtils.getStackTrace(e));
            throw new MyRuntimeException(ExceptionUtils.getStackTrace(e));
        }
        return true;
    }

    /**
     * 单据完成后
     *
     * @param formId
     */
    public Boolean finish(String formId) {
        try {
            PageData pageData = new PageData();
            pageData.put("status", String.valueOf(FINISH));
            pageData.put("id", Collections.singletonList(formId));
            bondsrepaymentDao.refer(pageData);
            PageData pd = bondsrepaymentDao.findbyid(formId);
            operation(pd);
//            saveMessage(formId, true, "审批通过");
        } catch (Exception e) {
            LOGGER.error(ExceptionUtils.getStackTrace(e));
            throw new MyRuntimeException(new ObjResult("单据流转完成时修改单据状态失败！"));
        }
        return true;
    }

    private void saveMessage(String formId, boolean approval, String comment) throws Exception{
        PageData pd = bondsrepaymentDao.findbyid(formId);
        String dataSource = pd.getString("dataSource");
        String dataSourceId = pd.getString("dataSourceId");
        if (YthConstant.DATA_NINGBO.equals(dataSource)) {
            ApprovalMessage approvalMessage = new ApprovalMessage();
            approvalMessage.setDataSourceType(YthConstant.DATA_NINGBO);
            approvalMessage.setFilingUserName(UserCache.userIdToName(TokenUtil.getTokenUserId()));
            approvalMessage.setFormType(FormTypeConstant.CQZC_BONDSREPAYMENT);
            approvalMessage.setDataSourceId(dataSourceId);
            approvalMessage.setOpinion(comment);
            approvalMessage.setIsApprove(approval ? 2 : 1);
            approvalMessage.setIsSend(1);
            approvalMessageService.save(approvalMessage);
        }
    }

    /**
     * @param formIds 单据ids
     */
    public List<PageData> findByIds(List<String> formIds) {
        try {
            PageData pageData = new PageData();
            pageData.put("ids", formIds);
            List<PageData> list = bondsrepaymentDao.findByIds(pageData);
            List<PageData> out = new ArrayList<>();
            for (PageData pd2 :list){
                String unitname = pd2.getString("UNITNAME");
                pd2.put("orgName",unitname);
                out.add(pd2);
            }
            return out;
        } catch (Exception e) {
            LOGGER.error(ExceptionUtils.getStackTrace(e));
            throw new MyRuntimeException(new ObjResult("根据单据id列表查询报表失败！"));
        }
    }

    @Override
    public List<Integer> getFormType() {
        return Arrays.asList(CQZC_BONDSREPAYMENT);
    }

    public void goBackToStash(String formId) {
        try {
            PageData pageData = new PageData();
            pageData.put("status", String.valueOf(UNREVIEWED));
            pageData.put("id", Collections.singletonList(formId));
            bondsrepaymentDao.refer(pageData);
//            backOperation(formId);
        } catch (Exception e) {
            LOGGER.error(ExceptionUtils.getStackTrace(e));
        }
    }

    /**
     * 退回操作
     *
     * @param id
     */
    private void backOperation(String id) throws Exception {
        PageData pd = bondsrepaymentDao.findbyid(id);
        //超短期
        if ("5".equals(pd.getString("bondVarieties"))) {
            PageData p = bondIssueDao.findbyid(pd.getString("bondIssueId"));
            //存续余额
            BigDecimal balance = new BigDecimal(pd.getString("balance"));
            //剩余可发债额度
            BigDecimal remaining_issuable_amount = new BigDecimal(p.getString("remainingIssuableAmount"));
            //操作存续余额
            String amount = remaining_issuable_amount.subtract(balance).toPlainString();
            p.put("remainingIssuableAmount", amount);
            bondIssueDao.edit(p);
        }
    }


    public ObjResult RemainingBalance(PageData pd) {
        try {
            ObjResult objResult = new ObjResult(CommonCode.SUCCESS);
            PageData p = new PageData();
            p.put("remainingBalance", RemainingBalance(pd.getString("bondIssueId")));
            objResult.setPageData(p);
            return objResult;
        } catch (Exception e) {
            LOGGER.error(ExceptionUtils.getStackTrace(e));
            return new ObjResult(CommonCode.ERROR);
        }
    }

    /**
     * 存续余额
     *
     * @param id 发行id
     * @return
     */
    private String RemainingBalance(String id) throws Exception {
        //发行
        PageData apply = bondIssueDao.findbyid(id);
        PageData p = new PageData();
        p.put("bondIssueId", id);
        //累计已偿还金额
        String sumRepay = bondsrepaymentDao.RemainingBalance(p);
        //发行金额
        String issueAmount = apply.getString("issueAmount");
        if (Tools.isEmpty(issueAmount)) {
            issueAmount = "0";
        }
        if (Tools.isEmpty(sumRepay)) {
            sumRepay = "0";
        }
        BigDecimal b_sumRepay = new BigDecimal(sumRepay);
        BigDecimal b_issueAmount = new BigDecimal(issueAmount);
        //存续余额
        return b_issueAmount.subtract(b_sumRepay).toPlainString();
    }

    public ListResult reportList(PageData pd) throws Exception {
        ListResult listResult;
        try {
            Page page = new Page(false, pd);
            List<PageData> list = bondsrepaymentDao.reportListPage(page);
            listResult = new ListResult(CommonCode.SUCCESS);
            listResult.setList(list);
            listResult.setTotal(page.getTotal());
        } catch (Exception e) {
            LOGGER.error(ExceptionUtils.getStackTrace(e));
            listResult = new ListResult(CommonCode.ERROR);
        }
        return listResult;
    }
    public ListResult reportListSix(PageData pd) throws Exception {
        ListResult listResult;
        try {
            Page page = new Page(false, pd);
            List<PageData> list = bondsrepaymentDao.reportListPageSix(page);
            listResult = new ListResult(CommonCode.SUCCESS);
            listResult.setList(list);
            listResult.setTotal(page.getTotal());
        } catch (Exception e) {
            LOGGER.error(ExceptionUtils.getStackTrace(e));
            listResult = new ListResult(CommonCode.ERROR);
        }
        return listResult;
    }

    public String ythSubmitBatch(String data){
        YthResult ythResult = new YthResult();
        //成功的id集合
        List<String> successIds = new ArrayList<>();
        //失败的id集合
        List<String> failIds = new ArrayList<>();
        //失败的原因
        List<String> failReasons = new ArrayList<>();
        //将json字符串转换成list
        List<BondsRepayment> dataList = JSON.parseArray(data, BondsRepayment.class);
        if (CollectionUtil.isEmpty(dataList)){
            failReasons.add("数据为空");
            ythResult.setFailReason(StringUtils.join(failReasons, StringPool.COMMA));
            return JSON.toJSONString(ythResult);
        }

        List<BondsIssue> bondsIssueList = bondsIssueService.list(Wrappers.<BondsIssue>lambdaQuery()
                .eq(BondsIssue::getDataSource, YthConstant.DATA_NINGBO).eq(BondsIssue::getStatus, FINISH));
        Map<String, BondsIssue> bondsIssueMap = bondsIssueList.stream().collect(Collectors.toMap(BondsIssue::getDataSourceId, Function.identity()));
        List<BondsRepayment> oldList = list(Wrappers.<BondsRepayment>lambdaQuery()
                .eq(BondsRepayment::getDataSource, YthConstant.DATA_NINGBO));
        Map<String, BondsRepayment> oldMap = oldList.stream().collect(Collectors.toMap(BondsRepayment::getDataSourceId, Function.identity()));
        List<String> cantSubmitStatus = Stream.of(String.valueOf(FINISH), String.valueOf(FLOW)).collect(Collectors.toList());
        List<String> cantSubmitList = oldList.stream().filter(item -> cantSubmitStatus.contains(item.getStatus()))
                .map(BondsRepayment::getId).collect(Collectors.toList());
        Date now = DateUtil.now();
        List<BondsRepayment> submitList = new ArrayList<>();
        for (BondsRepayment bondsRepayment : dataList){
            if (!bondsIssueMap.containsKey(bondsRepayment.getBondIssueId())){
                failIds.add(bondsRepayment.getDataSourceId());
                failReasons.add(bondsRepayment.getDataSourceId() + "债券发行数据不存在");
                continue;
            }
            if (cantSubmitList.contains(bondsRepayment.getDataSourceId())){
                failIds.add(bondsRepayment.getDataSourceId());
                failReasons.add(bondsRepayment.getDataSourceId() + "该数据已提交");
                continue;
            }
            BondsIssue bondsIssue = bondsIssueMap.get(bondsRepayment.getBondIssueId());
            successIds.add(bondsRepayment.getDataSourceId());
            bondsRepayment.setBondIssueId(bondsIssue.getId());
            bondsRepayment.setCode(bondsIssue.getCode());
            if (oldMap.containsKey(bondsRepayment.getDataSourceId())){
                bondsRepayment.setId(oldMap.get(bondsRepayment.getDataSourceId()).getId());
                bondsRepayment.setUpdateTime(now);
            }else {
                bondsRepayment.setCreateDate(now);
            }
            bondsRepayment.setFormType(String.valueOf(FormTypeConstant.CQZC_BONDSREPAYMENT));
            bondsRepayment.setDataSource(YthConstant.DATA_NINGBO);
            bondsRepayment.setOrgId(bondsIssue.getOrgId());
            bondsRepayment.setStatus(String.valueOf(UNREVIEWED));
            bondsRepayment.setCreateCompanyId(bondsIssue.getCreateCompanyId());
            submitList.add(bondsRepayment);
        }

        if (CollectionUtil.isNotEmpty(submitList)){
            saveOrUpdateBatch(submitList);
        }

        ythResult.setSuccessIds(successIds);
        ythResult.setFailIds(failIds);
        ythResult.setFailReason(StringUtils.join(failReasons, StringPool.COMMA));
        //ythResult转换成json字符串
        return JSON.toJSONString(ythResult);

    }
}